package maiyatian.videolive.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import maiyatian.videolive.IActivity;
import maiyatian.videolive.R;
import maiyatian.videolive.fragment.WebviewFragment;
import maiyatian.videolive.fragment.personCenter.AuthFragment;
import maiyatian.videolive.fragment.personCenter.ContributeFragment;
import maiyatian.videolive.fragment.personCenter.EditInfoFragment;
import maiyatian.videolive.fragment.personCenter.MyAccountFragment;
import maiyatian.videolive.fragment.personCenter.MyLevelFragment;
import maiyatian.videolive.fragment.personCenter.MyProfitFragment;
import maiyatian.videolive.fragment.personCenter.SettingListFragment;
import maiyatian.videolive.fragment.personCenter.WhisperFragment;
import maiyatian.videolive.fragment.personHome.LiveInfoFragment;

/**
 * Created by 王中阳 on 2016/5/10.
 */
@ContentView(R.layout.activity_person_center)
public class PersonCenterActivity extends IActivity implements View.OnClickListener {
    public static final String TAG = "PersonCenterActivity";
    //fragment初始化及实例化
    PersonCenterActivity mycontext;
    ActionBar ab;
    @ViewInject(R.id.titleBar)
    TextView titleBar;
    @ViewInject(R.id.back)
    ImageView back;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mycontext = this;
        x.view().inject(this);
        back.setOnClickListener(this);
        mPageTo = PersonCenterActivity.this.getIntent().getStringExtra(IActivity.PAGETO);
        switchFragment(mPageTo);
    }

    private void switchFragment(String mPageTo) {
        Fragment fragment = null;
        switch (mPageTo) {
            case AuthFragment.TAG:
                fragment = AuthFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.appAuth));
                break;
            case ContributeFragment.TAG:
                fragment = ContributeFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.contribute));
                break;
            case MyAccountFragment.TAG:
                fragment = MyAccountFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.myAccount));
                break;
            case MyLevelFragment.TAG:
                fragment = MyLevelFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.myLevel));
                break;
            case LiveInfoFragment.TAG:
                fragment = LiveInfoFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.myLive));
                break;
            case MyProfitFragment.TAG:
                fragment = MyProfitFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.myProfit));
                break;
            case SettingListFragment.TAG:
                fragment = SettingListFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.appSetting));
                break;
            case EditInfoFragment.TAG:
                fragment = EditInfoFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.editInfo));
                break;
            case WhisperFragment.TAG:
                fragment = WhisperFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.information));
                break;
            case WebviewFragment.TAG:
                fragment = WebviewFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.communityConvention));
                break;
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.boxPersonCenter, fragment).commit();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                this.finish();
                break;
        }
    }
}
